<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>盒子宽高</title>
    <style>
      .box {
        width: 200px;
        height: 200px;
        background-color: pink;
        padding: 10px;
        border: 10px solid red;
        /*  实际宽/高: 200+20+20 = 240 通过元素的offsetWidth/offsetHeight可以获取到 */
      }
      span {
        display: inline-block;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <span id="child"></span>
    </div>
    <div>
      <span></span>
    </div>
    <script>
      let ele = document.getElementById("child");
      console.log(
        "父元素的实际宽 content + padding + border-->>",
        ele.parentNode.offsetWidth
      );
      console.log(
        "父元素的实际高 content + padding + border-->>",
        ele.parentNode.offsetHeight
      );
    </script>
  </body>
</html>
